<html>
 <head>
  <link href="./leetcode-problem.css" rel="stylesheet" type="text/css">
 </head>
 <body>
  <div class="question_difficulty">
   难度：Medium
  </div>
  <div>
   <h1 class="question_title">
    12. Integer to Roman
   </h1>
   <p>
    Roman numerals are represented by seven different symbols:&nbsp;
    <code>
     I
    </code>
    ,
    <code>
     V
    </code>
    ,
    <code>
     X
    </code>
    ,
    <code>
     L
    </code>
    ,
    <code>
     C
    </code>
    ,
    <code>
     D
    </code>
    and
    <code>
     M
    </code>
    .
   </p>
   <pre>
<strong>Symbol</strong>       <strong>Value</strong>
I             1
V             5
X             10
L             50
C             100
D             500
M             1000</pre>
   <p>
    For example,&nbsp;two is written as
    <code>
     II
    </code>
    &nbsp;in Roman numeral, just two one's added together. Twelve is written as,
    <code>
     XII
    </code>
    , which is simply
    <code>
     X
    </code>
    +
    <code>
     II
    </code>
    . The number twenty seven is written as
    <code>
     XXVII
    </code>
    , which is
    <code>
     XX
    </code>
    +
    <code>
     V
    </code>
    +
    <code>
     II
    </code>
    .
   </p>
   <p>
    Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not
    <code>
     IIII
    </code>
    . Instead, the number four is written as
    <code>
     IV
    </code>
    . Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as
    <code>
     IX
    </code>
    . There are six instances where subtraction is used:
   </p>
   <ul>
    <li>
     <code>
      I
     </code>
     can be placed before
     <code>
      V
     </code>
     (5) and
     <code>
      X
     </code>
     (10) to make 4 and 9.&nbsp;
    </li>
    <li>
     <code>
      X
     </code>
     can be placed before
     <code>
      L
     </code>
     (50) and
     <code>
      C
     </code>
     (100) to make 40 and 90.&nbsp;
    </li>
    <li>
     <code>
      C
     </code>
     can be placed before
     <code>
      D
     </code>
     (500) and
     <code>
      M
     </code>
     (1000) to make 400 and 900.
    </li>
   </ul>
   <p>
    Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999.
   </p>
   <p>
    <strong>
     Example 1:
    </strong>
   </p>
   <pre>
<strong>Input:</strong>&nbsp;3
<strong>Output:</strong> "III"</pre>
   <p>
    <strong>
     Example 2:
    </strong>
   </p>
   <pre>
<strong>Input:</strong>&nbsp;4
<strong>Output:</strong> "IV"</pre>
   <p>
    <strong>
     Example 3:
    </strong>
   </p>
   <pre>
<strong>Input:</strong>&nbsp;9
<strong>Output:</strong> "IX"</pre>
   <p>
    <strong>
     Example 4:
    </strong>
   </p>
   <pre>
<strong>Input:</strong>&nbsp;58
<strong>Output:</strong> "LVIII"
<strong>Explanation:</strong> L = 50, V = 5, III = 3.
</pre>
   <p>
    <strong>
     Example 5:
    </strong>
   </p>
   <pre>
<strong>Input:</strong>&nbsp;1994
<strong>Output:</strong> "MCMXCIV"
<strong>Explanation:</strong> M = 1000, CM = 900, XC = 90 and IV = 4.</pre>
  </div>
  <div>
   <h1 class="question_title">
    12. 整数转罗马数字
   </h1>
   <p>
    罗马数字包含以下七种字符：&nbsp;
    <code>
     I
    </code>
    ，&nbsp;
    <code>
     V
    </code>
    ，&nbsp;
    <code>
     X
    </code>
    ，&nbsp;
    <code>
     L
    </code>
    ，
    <code>
     C
    </code>
    ，
    <code>
     D
    </code>
    &nbsp;和&nbsp;
    <code>
     M
    </code>
    。
   </p>
   <pre><strong>字符</strong>          <strong>数值</strong>
I             1
V             5
X             10
L             50
C             100
D             500
M             1000</pre>
   <p>
    例如， 罗马数字 2 写做&nbsp;
    <code>
     II
    </code>
    &nbsp;，即为两个并列的 1。12 写做&nbsp;
    <code>
     XII
    </code>
    &nbsp;，即为&nbsp;
    <code>
     X
    </code>
    &nbsp;+&nbsp;
    <code>
     II
    </code>
    &nbsp;。 27 写做&nbsp;&nbsp;
    <code>
     XXVII
    </code>
    , 即为&nbsp;
    <code>
     XX
    </code>
    &nbsp;+&nbsp;
    <code>
     V
    </code>
    &nbsp;+&nbsp;
    <code>
     II
    </code>
    &nbsp;。
   </p>
   <p>
    通常情况下，罗马数字中小的数字在大的数字的右边。但也存在特例，例如 4 不写做&nbsp;
    <code>
     IIII
    </code>
    ，而是&nbsp;
    <code>
     IV
    </code>
    。数字 1 在数字 5 的左边，所表示的数等于大数 5 减小数 1 得到的数值 4 。同样地，数字 9 表示为&nbsp;
    <code>
     IX
    </code>
    。这个特殊的规则只适用于以下六种情况：
   </p>
   <ul>
    <li>
     <code>
      I
     </code>
     &nbsp;可以放在&nbsp;
     <code>
      V
     </code>
     &nbsp;(5) 和&nbsp;
     <code>
      X
     </code>
     &nbsp;(10) 的左边，来表示 4 和 9。
    </li>
    <li>
     <code>
      X
     </code>
     &nbsp;可以放在&nbsp;
     <code>
      L
     </code>
     &nbsp;(50) 和&nbsp;
     <code>
      C
     </code>
     &nbsp;(100) 的左边，来表示 40 和&nbsp;90。&nbsp;
    </li>
    <li>
     <code>
      C
     </code>
     &nbsp;可以放在&nbsp;
     <code>
      D
     </code>
     &nbsp;(500) 和&nbsp;
     <code>
      M
     </code>
     &nbsp;(1000) 的左边，来表示&nbsp;400 和&nbsp;900。
    </li>
   </ul>
   <p>
    给定一个整数，将其转为罗马数字。输入确保在 1&nbsp;到 3999 的范围内。
   </p>
   <p>
    <strong>
     示例&nbsp;1:
    </strong>
   </p>
   <pre><strong>输入:</strong>&nbsp;3
<strong>输出:</strong> "III"</pre>
   <p>
    <strong>
     示例&nbsp;2:
    </strong>
   </p>
   <pre><strong>输入:</strong>&nbsp;4
<strong>输出:</strong> "IV"</pre>
   <p>
    <strong>
     示例&nbsp;3:
    </strong>
   </p>
   <pre><strong>输入:</strong>&nbsp;9
<strong>输出:</strong> "IX"</pre>
   <p>
    <strong>
     示例&nbsp;4:
    </strong>
   </p>
   <pre><strong>输入:</strong>&nbsp;58
<strong>输出:</strong> "LVIII"
<strong>解释:</strong> L = 50, V = 5, III = 3.
</pre>
   <p>
    <strong>
     示例&nbsp;5:
    </strong>
   </p>
   <pre><strong>输入:</strong>&nbsp;1994
<strong>输出:</strong> "MCMXCIV"
<strong>解释:</strong> M = 1000, CM = 900, XC = 90, IV = 4.</pre>
  </div>
 </body>
</html>